<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<%@include file="/view/resource.jsp" %>
	<link rel="stylesheet" type="text/css" href="${ctx}/css/base.css">
	<link rel="stylesheet" href="${ctx}/static/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
	<script type="text/javascript" src="${ctx}/static/plugins/ztree/js/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${ctx}/static/plugins/ztree/js/jquery.ztree.excheck.js"></script>
	<style type="text/css">
		.btnmr {
			margin: 3px 5px;
			width: 80px;
		}

		.panel-tool a.layout-button-up {
			display: none;
		}

	</style>
</head>
<body>
<div class="topjui-layout" data-options="fit:true">
	<div data-options="region:'west',split:false,width:300">
		<div title="" style="padding: 3px">
			<span style="margin-left: 100px;font-size:14px;color: #330099; ">指挥卡树形</span>
			<div style="margin-bottom: 5px">
				<select class="topjui-combobox" name="filterType" id="filterTypeCommand" style="width: 120px;"
				        data-options="panelHeight:105,value:'0'">
					<option value="设备号">设备号</option>
					<option value="显示名称">显示名称</option>
					<option value="分组名称">分组名称</option>
				</select>
				<input id="searchBoxCommand" class="topjui-searchbox"
				       style="width: 150px"/>
			</div>
			<ul id="deviceTreeCommand" class="ztree">
			</ul>
		</div>
	</div>
	<div data-options="region:'center'">
		<div title="" style="padding: 3px">
			<span style="margin-left: 100px;font-size:14px;color: #330099; ">未绑定普通卡树形</span>
			<div style="margin-bottom: 5px">
				<select class="topjui-combobox" name="filterType" id="filterType" style="width: 120px;"
				        data-options="panelHeight:105,value:'0'">
					<option value="设备号">设备号</option>
					<option value="显示名称">显示名称</option>
					<option value="分组名称">分组名称</option>
				</select>
				<input id="searchBox" class="topjui-searchbox"
				       style="width: 150px"/>
			</div>
			<ul id="deviceTree" class="ztree">
			</ul>
		</div>
	</div>
	<div data-options="region:'south',border:true"
	     style="text-align:right;height:38px;line-height:38px;border-bottom:0;overflow:hidden;">
		<a href="#" onclick="doBindDevice();" class="topjui-menubutton btnmr" data-options="iconCls:'fa fa-save',
				   btnCls:'topjui-btn'">绑定</a>
	</div>
</div>
<script type="text/javascript" src="${ctx}/js/deviceBind/commandCardTree.js"></script>
<script type="text/javascript" src="${ctx}/js/deviceBind/childCardTree.js"></script>
<script type="text/javascript" src="${ctx}/js/common/package.js"></script>
<script type="text/javascript" src="${ctx}/js/common/base.js?v=11"></script>
<script type="text/javascript">
	$(function () {
		//设备
		DeviceTree.createTree("deviceTree");

		CommandDeviceTree.createTree("deviceTreeCommand");

		$('#searchBox').searchbox({
			searcher: function (value, name) {
				var filterTypeValue = $("#filterType").combobox('getText');
				var filterType = "";
				if ("设备号" == filterTypeValue) {
					filterType = 0;
				}
				if ("显示名称" == filterTypeValue) {
					filterType = 1;
				}
				if ("分组名称" == filterTypeValue) {
					filterType = 2;
				}
				DeviceTree.Treefilter(filterType, value);
			},
			prompt: '条件查询',
		});
		$('#filterType').combobox("setValue", "设备号");


		$('#searchBoxCommand').searchbox({
			searcher: function (value, name) {
				var filterTypeValue = $("#filterTypeCommand").combobox('getText');
				var filterType = "";
				if ("设备号" == filterTypeValue) {
					filterType = 0;
				}
				if ("显示名称" == filterTypeValue) {
					filterType = 1;
				}
				if ("分组名称" == filterTypeValue) {
					filterType = 2;
				}
				CommandDeviceTree.Treefilter(filterType, value);
			},
			prompt: '条件查询',
		});
		$('#filterTypeCommand').combobox("setValue", "设备号");

	})


	function doBindDevice() {
		var simNos = [];

		var treeObj = $.fn.zTree.getZTreeObj("deviceTreeCommand");
		var nodes = treeObj.getCheckedNodes(true);

		if (nodes.length == 0) {
			$.iMessager.alert("提示", "请勾选左侧树形分组下指挥卡!", 'messager-warning');
			return;
		}
		var node;
		if (nodes.length > 0) {
			node = nodes[0];
		}

		var treeObjChild = $.fn.zTree.getZTreeObj("deviceTree");
		var nodesChild = treeObjChild.getCheckedNodes(true);
		if (nodesChild && nodesChild.length) {
			var selectDeviceIds = "";
			for (var i = 0, len = nodesChild.length; i < len; i++) {
				var nodeChild = nodesChild[i];
				if (typeof (nodeChild.children) == "undefined" && nodeChild.id.indexOf("v") == 0) {
					simNos.push('simNos=' + nodeChild.simNo);
				}
			}
		}

		if (simNos.length == 0) {
			$.iMessager.alert("提示", "请勾选未绑定卡!", 'messager-warning');
			return;
		}
		simNos.push('parentSim=' + node.simNo);
		var params = simNos.join("&");
		var url = path + "/deviceBind/deviceBind";
		$.ajax(url, {
			type: 'post',
			dataType: 'json',
			data: params,
			success: function (result) {
				if (result.success) {
					parent.$('#commandWindow').window('close');
					var param = parent.$("#searchForm").serializeObject();
					parent.$('#data-list').datagrid('reload', param);
				}
				else
					$.iMessager.alert("提示", result.msg, 'messager-error');
			},
		});
	}

</script>
</body>
</html>
